﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <WtmSearcher v-model="searchDataCustomConfig" @search="getTableDataCustomConfig">
      <el-row>
        
    <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="customProperty_FormItem" prop="customProperty" label="属性编码">
            <el-input v-model="searchDataCustomConfig.customProperty" clearable></el-input>
        </el-form-item>
    </el-col>
    <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="propertyDescribe_FormItem" prop="propertyDescribe" label="属性描述">
            <el-input v-model="searchDataCustomConfig.propertyDescribe" clearable></el-input>
        </el-form-item>
    </el-col>
    <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="propertyValue_FormItem" prop="propertyValue" label="属性值">
            <el-input v-model="searchDataCustomConfig.propertyValue" clearable></el-input>
        </el-form-item>
    </el-col>
      </el-row>

  </WtmSearcher>

  <div style="text-align: right;">
      <WtmButton v-auth="'/api/CustomConfig/Add'" icon='fa fa-plus' type='primary' :button-text="$t('message._system.common.vm.add')" @click="OnCreateClick()"/>
    <WtmButton v-auth="'/api/CustomConfig/BatchDelete'"  icon='fa fa-trash' type='danger' :button-text="$t('message._system.common.vm.batchdelete')" :confirm="$t('message._system.common.vm.deletetip')" @click="onBatchDelete()"/>
    <WtmButton v-auth="'/api/CustomConfig/Import'" icon='fa fa-tasks' type='primary' :button-text="$t('message._system.common.vm.import')" @click="OnImportClick()"/>
    <WtmButton v-auth="'/api/CustomConfig/CustomConfigExportExcel'"  icon='fa fa-arrow-circle-down' type='primary' :button-text="$t('message._system.common.vm.export')" @click="onExport()"/>

  </div>
  <WtmTable ref="tableRefCustomConfig" v-bind="tableDataCustomConfig">
    <template #operation>
      <el-table-column :label="$t('message._system.common.vm.operate')" width="180">
        <template v-slot="scope">
          <el-button text type="primary" @click="OnEditrowClick(scope.row)" v-auth="'/api/CustomConfig/Edit'">{{ $t('message._system.common.vm.edit') }}</el-button>
					<el-button text type="primary" @click="OnDetailsrowClick(scope.row)" v-auth="'/api/CustomConfig/{id}'">{{ $t('message._system.common.vm.detail') }}</el-button>
					<el-popconfirm :title="$t('message._system.common.vm.deletetip')"  @confirm="onDelete(scope.row)">
						<template #reference>
							<el-button text type="danger" v-auth="'/api/CustomConfig/BatchDelete'">{{ $t('message._system.common.vm.delete') }}</el-button>
						</template>
					</el-popconfirm>
        </template>
      </el-table-column>
    </template>
  </WtmTable>

</el-card>
</div>
</template>


<script setup lang="ts" name="自定义参数;true;TyMES.Controllers;CustomConfig">
import {  ElMessageBox, ElMessage } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { CustomConfigApi } from '/@/api/baseinformation/CustomConfig';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;

const CreateDialog = defineAsyncComponent(() => import('./create.vue'));
const EditDialog = defineAsyncComponent(() => import('./edit.vue'));
const DetailsDialog = defineAsyncComponent(() => import('./details.vue'));
const ImportDialog = defineAsyncComponent(() => import('./import.vue'));

const stateCustomConfig = reactive({
    
});

const searchDataCustomConfig = ref({
    			customProperty: null,
			propertyDescribe: null,
			propertyValue: null,

});

// 定义变量内容
const tableRefCustomConfig = ref();
const tableDataCustomConfig = ref({
    // 列表数据（必传）
    data: [],
	// 表头内容（必传，注意格式）
	header: [
  
        {title:'属性编码',key: 'customProperty',type: 'text',isCheck: true},
        {title:'属性描述',key: 'propertyDescribe',type: 'text',isCheck: true},
        {title:'属性值',key: 'propertyValue',type: 'text',isCheck: true},
	],
	// 配置项（必传）
	config: {
        total: 0, // 列表总数
		loading: true, // loading 加载
		isSerialNo: true, // 是否显示表格序号
		isSelection: true, // 是否显示表格多选
		isOperate: true, // 是否显示表格操作栏
	}
});
// 初始化表格数据
const getTableDataCustomConfig = () => {
    tableRefCustomConfig.value.doSearch(CustomConfigApi().search, searchDataCustomConfig.value)
        .catch((error: any) => {
			other.setFormError(ci, error);
		});
};
const OnCreateClick = () => {
    other.openDialog(ci.proxy.$t('message._system.common.vm.add'), CreateDialog, null, getTableDataCustomConfig)
};

const OnEditrowClick = (row: any) => {
    other.openDialog(ci.proxy.$t('message._system.common.vm.edit'), EditDialog, row, getTableDataCustomConfig)
};

const OnDetailsrowClick = (row: any) => {
    other.openDialog(ci.proxy.$t('message._system.common.vm.detail'), DetailsDialog, row, getTableDataCustomConfig)
};

// 删除
const onDelete = (row: any) => {
    CustomConfigApi().delete([row.ID]).then(() => { getTableDataCustomConfig()})
};

const onBatchDelete = () => {
    const selectedrows = tableRefCustomConfig.value.getSelectedRows();
    const selectedids = selectedrows.map((x: any) => x.ID);
    if (selectedids.length > 0)
      CustomConfigApi().delete(selectedids).then(() => { getTableDataCustomConfig()})
    else
      ElMessage.error(ci.proxy.$t('message._system.common.vm.check'));
};

const OnImportClick = () => {
    other.openDialog(ci.proxy.$t('message._system.common.vm.import'), ImportDialog, null, getTableDataCustomConfig)
};

const onExport = () => {
	const selected = tableRefCustomConfig.value.getSelectedRows();
	if (selected.length > 0) {
		CustomConfigApi().exportById(selected.map((x: any) => x.ID));
	}
	else {
		CustomConfigApi().export({});
	}
};

// 页面加载时
onMounted(() => {
     
        getTableDataCustomConfig();

});

// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

